package day16MysSQL;

import java.sql.*;
import java.util.Scanner;

public class Demo05Login {

    private static final String baseUrl = "jdbc:mysql://localhost:3306/2307e_04?useSSL=false&serverTimeZone=Asia/Shanghai\", \"root\", \"root";
    private static final String username = "root";
    private static final String password = "root";
    public static void main(String[] args) throws SQLException {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入账号");
        String us =sc.next();

        System.out.println("请输入密码");
        String pwd = sc.next();

        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        // 2.获得数据库连接
        Connection conn = DriverManager.getConnection(baseUrl, username, password);
        // String sql = String.format("select * from sys_user where username = '%s' and password = '%s'", username, password);
        PreparedStatement statement = conn.prepareStatement("select * from sys_user where username = ? and password = ?");

        statement.setString(1, us);
        statement.setString(2, pwd);

        ResultSet res = statement.executeQuery();
        while (res.next()) {
            System.out.println(res.getString("password"));
        }

    }
}
